import { useUserStore } from '@/store';

export function usePermission() {
  const userStore = useUserStore();
  let permissions = []
  try{
    permissions = JSON.parse(userStore.menu as string).permList  || []
  }catch{
    permissions = []
  }
  
  const hasPermission = (accesses: string[]): boolean => {
    return true
    if (!accesses || !accesses.length) return true;
    return permissions.some((item: string) => {
      if(Array.isArray(accesses)) {
        return accesses.includes(item);
      } else {
        return accesses === item
      }
    });
  };
  return { hasPermission };
}
